home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Utils / Forecastfox / Bin / forecastfox-0.8.5.1-fx+mz+ns.xpi / components / ffWeb.js < prev    next >
Encoding:
Text File  |  2006-02-18  |  5.0 KB  |  124 lines

  1. const CLASS_ID = Components.ID("{C8938285-B9B3-4895-8209-26273DD745E9}");
  2. const CLASS_NAME = "Forecastfox Web Component";
  3. const CONTRACT_ID = "@ensolis.com/forecastfox/web;1";
  4. /******************************************************************************
  5.  * ffWeb component
  6.  ******************************************************************************/
  7. function ffWeb() 
  8. {
  9.   var sbs = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService);
  10.   this._manager = Components.classes["@ensolis.com/forecastfox/manager;1"].getService(Components.interfaces.ffIManager);
  11.   this._bundle = sbs.createBundle("chrome://forecastfox/locale/forecastfox.properties");
  12.   this._prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
  13. };
  14.  
  15. //version information
  16. ffWeb.prototype.version = "0.8.5";
  17.  
  18. //install icon pack
  19. ffWeb.prototype.installIconPack = function (aName, aURL)
  20. {
  21.   try {  
  22.     // make sure using HTTP or HTTPS and a jar file
  23.     if (! /^https?:\/\/.+\.jar$/i.test(aURL))
  24.       throw "Unsupported icon pack URL";    
  25.      
  26.   } catch(e) {
  27.     this._prompt.alert(null, this._bundle.GetStringFromName("ff.web.icons.label"),this._bundle.GetStringFromName("ff.web.icons.failed"));
  28.     throw Components.results.NS_ERROR_INVALID_ARG;
  29.   };
  30.   
  31.   //create parameters
  32.   var array = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray);
  33.   var name = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
  34.   var url = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
  35.   name.data = aName;
  36.   url.data = aURL;
  37.   array.AppendElement(name);
  38.   array.AppendElement(url);
  39.  
  40.   //open install dialog
  41.   var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"].getService(Components.interfaces.nsIWindowWatcher)    
  42.   ww.openWindow(this._manager.getWindow(), "chrome://forecastfox/content/icons.xul", "", "chrome,centerscreen,modal,dialog,titlebar", array);  
  43. };
  44.     
  45. ///////////////////////////
  46. // nsIClassInfo  
  47. ffWeb.prototype.getInterfaces = function(aCount) {
  48.   var ifaces = new Array();
  49.   ifaces.push(Components.interfaces.ffIWeb);
  50.   ifaces.push(Components.interfaces.nsIClassInfo);
  51.   ifaces.push(Components.interfaces.nsISupports);
  52.   aCount.value = ifaces.length;
  53.   return ifaces;
  54. };  
  55. ffWeb.prototype.getHelperForLanguage = function(aLanguage) {return null;}
  56. ffWeb.prototype.contractID = CONTRACT_ID;  
  57. ffWeb.prototype.classID = CLASS_ID;
  58. ffWeb.classDescription = CLASS_NAME;
  59. ffWeb.prototype.flags = Components.interfaces.nsIClassInfo.DOM_OBJECT;
  60. ffWeb.implementationLanguage = Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT;
  61.    
  62. ///////////////////////////
  63. // nsISupports   
  64. ffWeb.prototype.QueryInterface = function (aIID) {
  65.   if (!aIID.equals(Components.interfaces.ffIWeb) && 
  66.       !aIID.equals(Components.interfaces.nsIClassInfo) &&
  67.       !aIID.equals(Components.interfaces.nsISupports))
  68.     throw Components.results.NS_ERROR_NO_INTERFACE;
  69.   return this;
  70. };
  71.  
  72. /******************************************************************************
  73.  * XPCOM Functions for construction and registration
  74.  ******************************************************************************/
  75. var gModule = {
  76.   _firstTime: true,
  77.   registerSelf: function(aCompMgr, aFileSpec, aLocation, aType)
  78.   {
  79.     if (this._firstTime) {
  80.       this._firstTime = false;
  81.       throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
  82.     };
  83.     aCompMgr = aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  84.     aCompMgr.registerFactoryLocation(CLASS_ID, CLASS_NAME, CONTRACT_ID, aFileSpec, aLocation, aType);
  85.  
  86.     //register as global javascript property
  87.     var catMgr = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
  88.     catMgr.addCategoryEntry("JavaScript global property", "forecastfox", CONTRACT_ID, true, true);    
  89.   },
  90.  
  91.   unregisterSelf: function(aCompMgr, aLocation, aType)
  92.   {
  93.     aCompMgr = aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  94.     aCompMgr.unregisterFactoryLocation(CLASS_ID, aLocation);
  95.     
  96.     //unregister as global javascript property
  97.     var catMgr = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
  98.     catMgr.deleteCategoryEntry("JavaScript global property", "forecastfox", CONTRACT_ID, true);    
  99.   },
  100.   
  101.   getClassObject: function(aCompMgr, aCID, aIID)
  102.   {
  103.     if (!aIID.equals(Components.interfaces.nsIFactory))
  104.       throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  105.  
  106.     if (aCID.equals(CLASS_ID))
  107.       return gFactory;
  108.  
  109.     throw Components.results.NS_ERROR_NO_INTERFACE;
  110.   },
  111.  
  112.   canUnload: function(aCompMgr) { return true; }
  113. };
  114.  
  115. var gFactory = {
  116.   createInstance: function (aOuter, aIID)
  117.   {
  118.     if (aOuter != null)
  119.       throw Components.results.NS_ERROR_NO_AGGREGATION;
  120.     return (new ffWeb()).QueryInterface(aIID);
  121.   }
  122. };
  123.  
  124. function NSGetModule(aCompMgr, aFileSpec) { return gModule; }